﻿using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace _SqlUtil使用特殊类型参数
{
    public class SqlUtil
    {
        public static string connString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

        public static DataTable GetDataTable(string strConn, string strSql, CommandType type,
            params SqlParameter[] para)
        {
            DataTable dt = new DataTable("result");
            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandText = strSql;
                    cmd.CommandType = type;
                    cmd.Parameters.AddRange(para);
                    using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                    {
                        sda.Fill(dt);
                    }
                }
            }

            return dt;
        }

    }
}